package demo16Calendar类;

import java.util.Calendar;

public class demo10 {
    public static void main(String[] args) {
        //1.创建Calendar对象 保护的无法直接new
        Calendar calendar = Calendar.getInstance();
        System.out.println(calendar.getTime().toLocaleString());//变成Date 在toLocaleString()
        System.out.println(calendar.getTimeInMillis());

        //2.获取各种时间信息
        //获取年
        int year = calendar.get(Calendar.YEAR);
        //月
        int month = calendar.get(Calendar.MONTH);
        //日
        int day = calendar.get(Calendar.DATE);//Date
        //小时
        int hour = calendar.get(Calendar.HOUR_OF_DAY);//HOUR12小时 HOUR_OF_DAY 24小时
        //分钟
        int minute = calendar.get(Calendar.MINUTE);
        //秒
        int second = calendar.get(Calendar.SECOND);
        //month 0为1月 11为12月
        System.out.println(year + "年" + (month+1) + "月" + day + "日" + hour + ":" + minute + ":" + second );

        //3.修改时间
        Calendar calendar2 = Calendar.getInstance();
        calendar2.set(Calendar.DAY_OF_MONTH, 7);
        System.out.println(calendar2.getTime().toLocaleString());

        //4.add方法修改时间
        calendar2.add(Calendar.HOUR, 1);
        calendar2.add(Calendar.HOUR, -2);
        System.out.println(calendar2.getTime().toLocaleString());

        //5.补充方法
        calendar2.add(Calendar.MONTH, 1);
        int max = calendar2.getActualMaximum(Calendar.DAY_OF_MONTH);
        int min = calendar2.getActualMinimum(Calendar.DAY_OF_MONTH);
        System.out.println(max);
        System.out.println(min);
    }
}
